//
//  JKOCRealmUpdateModelTests.m
//  JKOCRealmTests
//
//  Created by 王冲 on 2019/2/26.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <Realm/Realm.h>
#import "Student.h"
@interface JKOCRealmUpdateModelTests : XCTestCase

@end

@implementation JKOCRealmUpdateModelTests

#pragma mark 更新模型方式一：在事务中直接更新对象
-(void)testUpdateModel1{
    
    // 更新模型方式一：在事务中直接更新对象
    Student *student = [[Student alloc]initWithValue:@{@"studentId":@3,@"studentName":@"王小二"}];
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    
    [realm transactionWithBlock:^{
        // 写入数据
        [realm addObject:student];
    }];
    
    [realm transactionWithBlock:^{
        // 写入数据
        student.studentName = @"王冲";
    }];
 
}
    
#pragma mark 更新模型方式二：根据主键进行更新
-(void)testUpdateModel2{
    
    Student *student = [[Student alloc]initWithValue:@{@"studentId":@3,@"studentName":@"王小二"}];
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    [realm transactionWithBlock:^{
      
        [realm addOrUpdateObject:student];
    }];
}

#pragma mark 更新模型方式三
-(void)testUpdateModel3{
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    [realm transactionWithBlock:^{
        
        // [Student createOrUpdateInRealm:realm withValue:@{@"studentId":@3,@"studentName":@"二蛋子"}];
        [Student createOrUpdateInRealm:realm withValue:@[@3,@"二傻"]];
        
        
    }];
}

#pragma mark 更新模型方式四
-(void)testUpdateModel4{
    
    
}
    
@end
